
* Saving a log file
log using replication_logFile_stata.txt, replace text 

* Installing plottig
ssc install blindschemes, replace all
set scheme plottig

*REPLICATION FOR RESULTS IN MAIN TEXT

****************************************
*to be run on replication_data_tscs.dta*
****************************************

use replication_data_tscs.dta, clear

/* TABLE 2 */

qui: reg update c.diffgovw##i.party_rg_part##i.caltw_ap90_ i.country_id, cluster(election_id)
margins, dydx(party_rg_part) at(diffgovw=(2.85)) over(caltw_ap90_) noci vsquish cformat(%3.2f) pformat(%5.3f) sformat(%3.2f)

/* FIGURE 1 */

qui: reg update c.diffgovw##i.party_rg_part##i.caltw_ap90_ i.country_id, cluster(election_id)

qui: margins r.party_rg_part@caltw_ap90_, at(diffgovw=(-7(1)7))
qui: marginsplot, level(95) yline(0) ///
	title("") xtitle("Distance to Real Government Position", margin(small)) ytitle("Contrasts of Linear Prediction" "(Gov. v. Opp. on Update)") ///
	legend(order(3 "WITHOUT Viable Alternative") position(6) cols(2)) ///
	ylabel(-3(1)3) ///
	plot1opts(lcolor(plb1) mcolor(plb1)) ci1opts(lcolor(plb1) mcolor(plb1)) plot2opts(lcolor(none) mcolor(none)) ci2opts(lcolor(none) mcolor(none)) ///
	graphregion(margin(vsmall)) plotregion(margin(small)) ///
	addplot(scatter rug_where diffgovw if tag_distrgw & e(sample) & caltw_ap90==1, plotr(m(b 4)) ms(none) mlabcolor(plr1) mlabel(rug_pipe) mlabpos(0) legend(order(3 "WITHOUT Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3))  || ///
	scatter rug_where diffgovw if tag_distrgw & e(sample) & caltw_ap90==0, plotr(m(b 4)) ms(none) mlabcolor(plb1) mlabel(rug_pipe) mlabpos(0) legend(order(3 "WITHOUT Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)))
qui: graph save mainwithout, replace

qui: margins r.party_rg_part@caltw_ap90_, at(diffgovw=(-7(1)7))
qui: marginsplot, level(95) yline(0) ///
	title("") xtitle("Distance to Real Government Position", margin(small)) ytitle("Contrasts of Linear Prediction" "(Gov. v. Opp. on Update)") ///
	legend(order(4 "WITH Viable Alternative") position(6) cols(2)) ///
	ylabel(-3(1)3) ///
	plot1opts(lcolor(none) mcolor(none)) ci1opts(lcolor(none) mcolor(none)) plot2opts(lcolor(plr1) mcolor(plr1)) ci2opts(lcolor(plr1) mcolor(plr1)) ///
	graphregion(margin(vsmall)) plotregion(margin(small)) ///
	addplot(scatter rug_where diffgovw if tag_distrgw & e(sample) & caltw_ap90==1, plotr(m(b 4)) ms(none) mlabcolor(plr1) mlabel(rug_pipe) mlabpos(0) legend(order(4 "WITH Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)) || ///
	scatter rug_where diffgovw if tag_distrgw & e(sample) & caltw_ap90==0, plotr(m(b 4)) ms(none) mlabcolor(plb1) mlabel(rug_pipe) mlabpos(0) legend(order(4 "WITH Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)))
qui: graph save mainwith, replace

graph combine mainwithout.gph mainwith.gph



********************************************
*to be run on replication_data_panelnor.dta*
********************************************

use replication_data_panelnor.dta, clear


/* FIGURE 2 */

twoway 	(kdensity sp_pre , bwidth(1) lc("ply3") lw(medthick)) ///
		(kdensity sp_post, bwidth(1) lc("plg2") lw(medthick)) ///
		, by(unexp, note("") legend(pos(6))) ///
		legend(cols(2) order(1 "Position Attributed to Sp Before Coalition (t)" 2 "Position Attributed to Sp After Coalition (t+1)") size(small)) ///
		subtitle(, size(small)) xtitle("") ///
		xlabel(0(1)10)


/* TABLE 3 */

ttest update_sp if sp_pre!=. & sp_post!=., by(unexp)


*--------------------------------------------------------------------------------------------------------------------------------------------------------*


*REPLICATION FOR RESULTS IN SUPPORTING INFORMATION

****************************************
*to be run on replication_data_tscs.dta*
****************************************

use replication_data_tscs.dta, clear


/* TABLE A1 */

qui: reg update c.diffgovw##i.party_rg_part##i.caltw_ap90_ i.country_id, cluster(election_id)
tabstat party_rg_part left_right_p update updateabs diffgovw diffgov diffgovw_abs diffgov_abs if e(sample), s(mean p50 sd) c(s) format(%9.2f) labelwidth(25)
tabstat caltw_ap90 caltwmwc if e(sample) & party_rg_part==1, s(mean p50 sd) c(s) format(%9.2f)


/* TABLE A2 */

ssc install estout, replace

eststo clear

qui: eststo: reg update c.diffgovw##i.party_rg_part##i.caltw_ap90_ i.country_id, cluster(election_id)

estout , cells(b(star fmt(2)) se(par fmt(2))) nobase label varwidth(70) mlabels(,dep) drop(*.country_id)


/* FIGURE A1 */

qui: reg update c.diffgov##i.party_rg_part##i.calt_ap90_ i.country_id, cluster(election_id)

qui: margins r.party_rg_part@calt_ap90_, at(diffgov=(-7(1)7))
qui: marginsplot, level(95) yline(0) ///
	title("") xtitle("Distance to Real Government Position", margin(small)) ytitle("Contrasts of Linear Prediction" "(Gov. v. Opp. on Update)") ///
	legend(order(3 "WITHOUT Viable Alternative") position(6) cols(2)) ///
	ylabel(-3(1)3) ///
	plot1opts(lcolor(plb1) mcolor(plb1)) ci1opts(lcolor(plb1) mcolor(plb1)) plot2opts(lcolor(none) mcolor(none)) ci2opts(lcolor(none) mcolor(none)) ///
	graphregion(margin(vsmall)) plotregion(margin(small)) ///
	addplot(scatter rug_where diffgov if tag_distrgu & e(sample) & calt_ap90==1, plotr(m(b 4)) ms(none) mlabcolor(plr1) mlabel(rug_pipe) mlabpos(0) legend(order(3 "WITHOUT Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3))  || ///
	scatter rug_where diffgov if tag_distrgu & e(sample) & calt_ap90==0, plotr(m(b 4)) ms(none) mlabcolor(plb1) mlabel(rug_pipe) mlabpos(0) legend(order(3 "WITHOUT Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)))
qui: graph save app1without, replace

qui: margins r.party_rg_part@calt_ap90_, at(diffgov=(-7(1)7))
qui: marginsplot, level(95) yline(0) ///
	title("") xtitle("Distance to Real Government Position", margin(small)) ytitle("Contrasts of Linear Prediction" "(Gov. v. Opp. on Update)") ///
	legend(order(4 "WITH Viable Alternative") position(6) cols(2)) ///
	ylabel(-3(1)3) ///
	plot1opts(lcolor(none) mcolor(none)) ci1opts(lcolor(none) mcolor(none)) plot2opts(lcolor(plr1) mcolor(plr1)) ci2opts(lcolor(plr1) mcolor(plr1)) ///
	graphregion(margin(vsmall)) plotregion(margin(small)) ///
	addplot(scatter rug_where diffgov if tag_distrgu & e(sample) & calt_ap90==1, plotr(m(b 4)) ms(none) mlabcolor(plr1) mlabel(rug_pipe) mlabpos(0) legend(order(4 "WITH Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3))  || ///
	scatter rug_where diffgov if tag_distrgu & e(sample) & calt_ap90==0, plotr(m(b 4)) ms(none) mlabcolor(plb1) mlabel(rug_pipe) mlabpos(0) legend(order(4 "WITH Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)))
qui: graph save app1with, replace

graph combine app1without.gph app1with.gph



/* TABLE A3 */

use replication_data_tscsmwc.dta, clear

tabstat mwc_total nparties, by(countryyear) labelwidth(25) nototal format(%5.3g)



/* FIGURE A2 */

use replication_data_tscs.dta, clear

qui: reg update c.diffgovw##i.party_rg_part##i.caltwmwc i.country_id if sample==1, cluster(election_id)

qui: margins r.party_rg_part@caltwmwc, at(diffgovw=(-7(1)7))
qui: marginsplot, level(95) yline(0) ///
	title("") xtitle("Distance to Real Government Position", margin(small)) ytitle("Contrasts of Linear Prediction" "(Gov. v. Opp. on Update)") ///
	legend(order(3 "WITHOUT Viable Alternative") position(6) cols(2)) ///
	ylabel(-3(1)3) ///
	plot1opts(lcolor(plb1) mcolor(plb1)) ci1opts(lcolor(plb1) mcolor(plb1)) plot2opts(lcolor(none) mcolor(none)) ci2opts(lcolor(none) mcolor(none)) ///
	graphregion(margin(vsmall)) plotregion(margin(small)) ///
	addplot(scatter rug_where diffgovw if tag_distrgw & e(sample) & caltwmwc==1, plotr(m(b 4)) ms(none) mlabcolor(plr1) mlabel(rug_pipe) mlabpos(0) legend(order(3 "WITHOUT Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3))  || ///
	scatter rug_where diffgovw if tag_distrgw & e(sample) & caltwmwc==0, plotr(m(b 4)) ms(none) mlabcolor(plb1) mlabel(rug_pipe) mlabpos(0) legend(order(3 "WITHOUT Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)))
qui: graph save app2without, replace

qui: margins r.party_rg_part@caltwmwc, at(diffgovw=(-7(1)7))
qui: marginsplot, level(95) yline(0) ///
	title("") xtitle("Distance to Real Government Position", margin(small)) ytitle("Contrasts of Linear Prediction" "(Gov. v. Opp. on Update)") ///
	legend(order(4 "WITH Viable Alternative") position(6) cols(2)) ///
	ylabel(-3(1)3) ///
	plot1opts(lcolor(none) mcolor(none)) ci1opts(lcolor(none) mcolor(none)) plot2opts(lcolor(plr1) mcolor(plr1)) ci2opts(lcolor(plr1) mcolor(plr1)) ///
	graphregion(margin(vsmall)) plotregion(margin(small)) ///
	addplot(scatter rug_where diffgovw if tag_distrgw & e(sample) & caltwmwc==1, plotr(m(b 4)) ms(none) mlabcolor(plr1) mlabel(rug_pipe) mlabpos(0) legend(order(4 "WITH Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3))  || ///
	scatter rug_where diffgovw if tag_distrgw & e(sample) & caltwmwc==0, plotr(m(b 4)) ms(none) mlabcolor(plb1) mlabel(rug_pipe) mlabpos(0) legend(order(4 "WITH Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)))
qui: graph save app2with, replace

graph combine app2without.gph app2with.gph


/* FIGURE A3 */

qui: reg left_right_p c.left_right c.diffgovw##i.caltw_ap90_##i.party_rg_part i.party_id, cluster(election_id)

qui: margins r.party_rg_part@caltw_ap90_, at(diffgovw=(-7(1)7))
qui: marginsplot, level(95) yline(0) ///
	title("") xtitle("Distance to Real Government Position") ytitle("Contrasts of Linear Prediction" "(Gov. v. Opp. on Update)") ///
	legend(order(3 "WITHOUT Viable Alternative") position(6) cols(2)) ///
	ylabel(-3(1)3) ///
	plot1opts(lcolor(plb1) mcolor(plb1)) ci1opts(lcolor(plb1) mcolor(plb1)) plot2opts(lcolor(none) mcolor(none)) ci2opts(lcolor(none) mcolor(none)) ///
	graphregion(margin(vsmall)) plotregion(margin(small)) ///
	addplot(scatter rug_where diffgovw if tag_distrgw & e(sample) & caltw_ap90==1, plotr(m(b 4)) ms(none) mlabcolor(plr1) mlabel(rug_pipe) mlabpos(0) legend(order(3 "WITHOUT Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3))  || ///
	scatter rug_where diffgovw if tag_distrgw & e(sample) & caltw_ap90==0, plotr(m(b 4)) ms(none) mlabcolor(plb1) mlabel(rug_pipe) mlabpos(0) legend(order(3 "WITHOUT Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)))
qui: graph save app3without, replace

qui: margins r.party_rg_part@caltw_ap90_, at(diffgovw=(-7(1)7))
qui: marginsplot, level(95) yline(0) ///
	title("") xtitle("Distance to Real Government Position") ytitle("Contrasts of Linear Prediction" "(Gov. v. Opp. on Update)") ///
	legend(order(4 "WITH Viable Alternative") position(6) cols(2)) ///
	ylabel(-3(1)3) ///
	plot1opts(lcolor(none) mcolor(none)) ci1opts(lcolor(none) mcolor(none)) plot2opts(lcolor(plr1) mcolor(plr1)) ci2opts(lcolor(plr1) mcolor(plr1)) ///
	graphregion(margin(vsmall)) plotregion(margin(small)) ///
	addplot(scatter rug_where diffgovw if tag_distrgw & e(sample) & caltw_ap90==1, plotr(m(b 4)) ms(none) mlabcolor(plr1) mlabel(rug_pipe) mlabpos(0) legend(order(4 "WITH Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)) || ///
	scatter rug_where diffgovw if tag_distrgw & e(sample) & caltw_ap90==0, plotr(m(b 4)) ms(none) mlabcolor(plb1) mlabel(rug_pipe) mlabpos(0) legend(order(4 "WITH Viable Alternative")) xlabel(-7(1)7) xscale(range(-7(1)7)) ylabel(-3(1)3) yscale(range(-3(1)3)))
qui: graph save app3with, replace

graph combine app3without.gph app3with.gph



********************************************
*to be run on replication_data_panelnor.dta*
********************************************

use replication_data_panelnor.dta, clear


/* FIGURE B1 */

twoway 	(kdensity update_sp if unexp==0, bwidth(1) lc("plb1") lw(medthick)) ///
		(kdensity update_sp if unexp==1, bwidth(1) lc("plr1") lw(medthick)) ///
		, legend(cols(2) pos(6) order(1 "Coalition that Formed Seen as Ideologically Closer" 2 "Alternative Coalition Seen as Ideologically Closer") size(vsmall)) ///
		ytitle("") xtitle("") ///
		xlabel(-8(1)8)


/* TABLE B1 */

eststo clear

qui: eststo m1: reg update_sp i.unexp
qui: eststo m2: reg update_sp i.unexp##c.dist_rg_sp sp_pre
qui: eststo m3: reg update_sp i.unexp##c.dist_rg_sp sp_pre self_pre
qui: eststo m4: reg update_sp i.unexp##c.dist_rg_sp sp_pre self_pre i.education i.agegroup

estout m1 m2 m3 m4, cells(b(star fmt(2)) se(par fmt(2))) starlevels(* 0.05) nobase label varwidth(50) drop(sp_pre self_pre *.education *.agegroup)


/* FIGURE B4 */

qui: reg update_sp i.unexp##c.dist_rg_sp sp_pre self_pre i.education i.agegroup

qui: margins, at(dist_rg_sp=(-7(1)6)) over(unexp) level(95)
marginsplot, level(95) yline(0, lpattern(dash)) title("") plot1opts(lcolor(plb1) mcolor(plb1)) ci1opts(lcolor(plb1) mcolor(plb1)) plot2opts(lcolor(plr1) mcolor(plr1)) ci2opts(lcolor(plr1) mcolor(plr1)) ///
			 ytitle("Update (Linear Prediction)") legend(cols(2) pos(6) order(3 "WITHOUT Viable Alternative" 4 "WITH Viable Alternative")) xtitle("Attributed Distance of Sp to Real Government") ///
			 addplot(scatter rug_where dist_rg_sp if tag_distrg & unexp==0, plotr(m(b 4)) ms(none) mlabcolor(plb1) mlabel(rug_pipe) mlabpos(0) legend(cols(2) pos(6) order(3 "WITHOUT Viable Alternative" 4 "WITH Viable Alternative")) xlabel(-7(1)6) xscale(range(-7(1)6)) || ///
			 scatter rug_where dist_rg_sp if tag_distrg & unexp==1, plotr(m(b 4)) ms(none) mlabcolor(plr1) mlabel(rug_pipe) mlabpos(0) legend(cols(2) pos(6) order(3 "WITHOUT Viable Alternative" 4 "WITH Viable Alternative")) xlabel(-7(1)6) xscale(range(-7(1)6)))
			 


/* FIGURE B5 */

twoway	(scatter update_sp dist_rg_sp if unexp==0, mc(plb1)) ///
		(scatter update_sp dist_rg_sp if unexp==1, mc(plr1)) ///
		(lpolyci update_sp dist_rg_sp if unexp==0, level(95) degree(0) clc(plb1)) ///
		(lpolyci update_sp dist_rg_sp if unexp==1, level(95) degree(0) clc(plr1)) ///
		, ytitle("Update") xtitle("Attributed Distance of Sp to Real Government") legend(cols(2) pos(6) order(4 "WITHOUT Viable Alternative" 6 "WITH Viable Alternative")) ///
		xlabel(-7(1)6) ylabel(-8(2)8)


log close

